package my.maven.project.web;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import my.maven.project.entity.Organization;
import my.maven.project.service.OrganizationService;

@Controller
public class HomeController {
	@Autowired
	private OrganizationService _organizationService;
	
	@RequestMapping("index")
	public String index()
	{
		return "index";
	}
	
	@RequestMapping("hello")
	@ResponseBody
	public String hello()
	{
		return "hello";
	}
	
	@RequestMapping("orgAdd")
	public String orgAdd()
	{
		return "views/orgAdd";
	}
	
	
	@RequestMapping(value="add",method= {RequestMethod.GET,RequestMethod.POST})
	public String Add(Organization org)
	{
		org.setCreateDate(new Date());
		org.setDeleted(false);
		org.setStatus(0);
//		_organizationService.insert(org);
		_organizationService.testPropagation(org, 4l);
		
//		return "forward:/api/org/list";
		return "redirect:/api/org/list";
	}
	
	@RequestMapping("del")
	public String delete(long id)
	{
		_organizationService.delete(id);
		return "redirect:/api/org/list";
	}

}
